package com.whu.waterworks.action;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.RealtimedataId;
import com.whu.waterworks.model.TempData;
import com.whu.waterworks.model.TempDataId;
import com.whu.waterworks.service.DataService;
import com.whu.waterworks.service.TempDataService;

public class SaveData extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String type;
	//private String waterPlantCode;
	private String time;
	private String stationCode;
	private String value;
	
	private String result;
	private DataService dataService;
	private TempDataService tempDataService;
	
	
	
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("%%%%%%SaveData stationCode="+stationCode+" time="+time+" type="+type+" value="+value);
		//先删除临时表里面的数据
		if(tempDataService.getData(stationCode, time, type)!=null)
		{
			TempData tempData = new TempData();
			TempDataId rid = new TempDataId();
			rid.setStationnum(stationCode);
			rid.setTime(time);
			rid.setType(type);
			tempData.setId(rid);
			tempData.setValue(value);
			if(tempDataService.deletData(tempData))
			{
				
				result=dataService.saveData(type,time,stationCode,value);
			}
			else {
				result = "FAIL";
			}
		}
		else {
			result=dataService.saveData(type,time,stationCode,value);
		}
		return super.execute();
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	/*public String getWaterPlantCode() {
		return waterPlantCode;
	}
	public void setWaterPlantCode(String waterPlantCode) {
		this.waterPlantCode = waterPlantCode;
	}*/
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public String getStationCode() {
		return stationCode;
	}
	public void setStationCode(String stationCode) {
		this.stationCode = stationCode;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public DataService getDataService() {
		return dataService;
	}
	public void setDataService(DataService dataService) {
		this.dataService = dataService;
	}
	public TempDataService getTempDataService() {
		return tempDataService;
	}
	public void setTempDataService(TempDataService tempDataService) {
		this.tempDataService = tempDataService;
	}
}
